﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace DBSourceToolsLib.CodeParser
{
    public class ParseTable : ParseObject
    {
        public const int TABLE = 1;
        private static Hashtable m_KeywordHash;

        public static void ClearTableList() {
            m_KeywordHash.Clear();
        }

        public ParseTable(string strValue, int iLineIdx, int iWordIdx)
            : base(ParseObject.UNKNOWN, ParseObject.TABLE, false, iLineIdx, iWordIdx)
        {
            m_Value = computeValue(strValue.Trim());
            if (m_Value > 0)
                IsResolved = true;
            m_Data = strValue.Trim();
        }

        public static int computeValue(string strValue)
        {
            if (m_KeywordHash.ContainsKey(strValue.ToLower()))
                return (int)m_KeywordHash[strValue.ToLower()];
            else
                return -1;
        }

        static ParseTable()
        {
            m_KeywordHash = new Hashtable();
        }

        public static void AddTable(string strTableName) {
            if (!m_KeywordHash.ContainsKey(strTableName))
            {
                m_KeywordHash.Add(strTableName.ToLower(), TABLE);
            }
        }

        public ParseTable(string strCurrentValue, object oNextChar, int iLineIdx, int iWordIdx)
            : base(ParseObject.UNKNOWN, ParseObject.VERB, false, iLineIdx, iWordIdx)
        {
            m_Value = computeValue(strCurrentValue.Trim(), oNextChar);
            if (m_Value > 0)
                IsResolved = true;
            m_Data = strCurrentValue.Trim();
        }

        public static int computeValue(string strCurrentValue, object oNextChar)
        {
            if (oNextChar != null)
            {
                char cNextChar = (char)oNextChar;
                if (char.IsLetterOrDigit(cNextChar))
                    return -1;
                else
                    return computeValue(strCurrentValue);
            }
            else
            {
                return computeValue(strCurrentValue);
            }
        }
        public bool IsLegal
        {
            get { return m_Value > 0; }
        }


    }
}
